package algorithm.number;

/**
 * 数字翻转
 * 翻转一个数字，忽略符号
 */
public class ReverseNumber {

    public int reverse(int n) {
        n = Math.abs(n);
        if(n<10) {
            return n;
        }

        StringBuilder builder = new StringBuilder();
        while(n >= 10) {
            int num = n % 10;
            builder.append(num);
            n = n / 10;
        }
        builder.append(n);

        return Integer.valueOf(builder.toString());
    }

    public static void main(String[] args) {
        System.out.println(new ReverseNumber().reverse(123));
    }
}
